package br.com.usp.server;
 
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
 



import br.com.usp.shared.BMMDTO;
 

@Entity(name="TB_BMMEXTENSION")
public class BMM {
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="ID_ENTIDADE")
    private int id;
	
	@Column(name="Nome")
	private String Descricao;
	
	@Column
    private String Tipo;
	
    @Column(name="Descricao")
    private String Representacao;
    
    @Column(name="ESQ")
	private int  left;
    
    @Column(name="CIMA")
	private int   top;

    @ManyToOne 
    @JoinColumn(name="ID_DIAGRAMA", referencedColumnName="ID_DIAGRAMA") 
    private Diagrama diagrama;

    @OneToMany(cascade=CascadeType.ALL ,mappedBy="de")
    private List<ConnectorBMM> listaConnectorDe;
    
    @OneToMany(cascade=CascadeType.ALL ,mappedBy="para")
    private List<ConnectorBMM> listaConnectorPara;
 
    
    @OneToMany(cascade=CascadeType.ALL ,mappedBy="processo")
	private List<ConnectorProcess> connectorProcess;
	
    
    @OneToMany(cascade=CascadeType.ALL ,mappedBy="processo")
	private List<ProcessFlow> listaProcess;
    
    
    public Diagrama getDiagrama() {
		return diagrama;
	}

	public void setDiagrama(Diagrama diagrama) {
		this.diagrama = diagrama;
	}

	public BMM()
    {
    	
		listaProcess = new ArrayList<ProcessFlow>(); 
		listaConnectorPara = new ArrayList<ConnectorBMM>();
		listaConnectorDe = new ArrayList<ConnectorBMM>();
    	
    }
    
    public BMM(BMMDTO bmm)
    {
    	this.id = bmm.getId();
    	this.Descricao = bmm.getDescricao();
    	this.Tipo = bmm.getTipo();
        this.Representacao = bmm.getRepresentacao();
        this.left = bmm.getLeft();
        this.top = bmm.getTop();
        listaProcess = new ArrayList<ProcessFlow>(); 
		listaConnectorPara = new ArrayList<ConnectorBMM>();
		listaConnectorDe = new ArrayList<ConnectorBMM>();
    }
    
    
    
 

	public List<ConnectorProcess> getConnectorProcess() {
		return connectorProcess;
	}

	public void setConnectorProcess(List<ConnectorProcess> connectorProcess) {
		this.connectorProcess = connectorProcess;
	}

	public List<ProcessFlow> getListaProcess() {
		return listaProcess;
	}

	public void setListaProcess(List<ProcessFlow> listaProcess) {
		this.listaProcess = listaProcess;
	}

	public List<ConnectorBMM> getListaConnectorDe() {
		if(listaConnectorDe == null)
			listaConnectorDe = new ArrayList<ConnectorBMM>();
		return listaConnectorDe;
	}

	public void setListaConnectorDe(List<ConnectorBMM> listaConnectorDe) {
		this.listaConnectorDe = listaConnectorDe;
	}

	public List<ConnectorBMM> getListaConnectorPara() {
		if(listaConnectorPara == null)
			listaConnectorPara = new ArrayList<ConnectorBMM>();
		return listaConnectorPara;
	}

	public void setListaConnectorPara(List<ConnectorBMM> listaConnectorPara) {
		this.listaConnectorPara = listaConnectorPara;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getDescricao() {
		return Descricao;
	}

	public void setDescricao(String descricao) {
		Descricao = descricao;
	}

	public String getTipo() {
		return this.Tipo;
	}

	public void setTipo(String tipo) {
		Tipo = tipo;
	}

	public String getRepresentacao() {
		return Representacao;
	}

	public void setRepresentacao(String representacao) {
		Representacao = representacao;
	}

	public int getLeft() {
		return left;
	}

	public void setLeft(int left) {
		this.left = left;
	}

	public int getTop() {
		return top;
	}

	public void setTop(int top) {
		this.top = top;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BMM other = (BMM) obj;
		if (id != other.id)
			return false;
		return true;
	}
    
	
	
}
